/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.artezio.buyndrive.service.impl;

import com.artezio.buyndrive.dao.UserDAO;
import com.artezio.buyndrive.domain.Users;
import com.artezio.buyndrive.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpSession;

/**
 *
 * @author vgordievich
 */
@Service
public class UserServiceImpl extends AbstractService<Users, UserDAO> 
    implements UserService{
    
    @Autowired
    @Override
    public void setDao(UserDAO dao) {
        super.dao = dao;
    }
    @Transactional
    @Override
    public Users login(String email, String password) {
              
        Users user = dao.getUser(email);
        if (user != null && user.getPassword().equals(password) 
                && user.getIsActive()) {
            return user;
        } else {
            return null;
        }
        
    }
    
    @Transactional
    @Override
    public Users get(String email) {
        return dao.getUser(email);
    }

    public Users userSessionRetrieve(HttpSession session){
        Users user = (Users) session.getAttribute("user");
        if (user == null){
            user = new Users();
        }
        return user;
    }
    
}
